const config = require("./config");
const Client = require("./client");
const storage = require('./db/index');
class SyncBlock {
    constructor(nodeUrl_pruning) {
        this.nodeUrl = nodeUrl_pruning;
        this.client = new Client(nodeUrl_pruning);
        this.logger = global.appLogger;
    }

    async getOneBlock(number) {
        try{
            let client = await this.client.getClient();
            let block = await client.getBlock(number);
            let blockCol = storage.getBlockCol();

            let docs = await blockCol.insertBlock(number,block);

            console.log(docs);
        }catch (e){
            this.logger.error('getOneBlock, e: ',e);
            throw e;
        }
    }
    async scanBlock(from, to) {
        try {
            for(let i=from ; i<=to; i++) {
                await this.getOneBlock(i);
            }
        }catch (e) {
            this.logger.error('scanBlock e: ',e);
        }

    }
}

module.exports = SyncBlock;